/**
 * Created by Administrator on 2017/4/20.
 */
import XLSX from 'xlsx';
export default ($scope,$http) => {
  //所有的中间文件
    $scope.middle = {};
  //展示文件树
    $scope.fileShow= {};
    $scope.attrArr = null;
    $scope.lidata = [];
    $scope.type = 'dirName';
  //获取文件树数据
    $http.get('api/fileTree').then(function (data) {
      $scope.allDir = data.data.data;
      for(var i = 0 ; i <$scope.allDir.length;i++ ){
        $scope.lidata.push($scope.allDir[i].dir);
      };
      $scope.middle.allDir = angular.extend({},data.data.data);
    });

  //文件树的展开
    $scope.show = function (name) {
      $scope.fileShow[name]?($scope.fileShow[name]= false):($scope.fileShow[name]= true);
    };
    $scope.getData = function (data) {
      $scope.attrArr = data;
      console.log(data);
    };
    $scope.read = function (workbook) {
      /* DO SOMETHING WITH workbook HERE */
      console.log(workbook);
      var sh ;
      var persons = [];
      console.log(XLSX.utils);
      for (var sheet in workbook.Sheets) {
        if (workbook.Sheets.hasOwnProperty(sheet)) {
            sh = workbook.Sheets[sheet];
            console.log(XLSX.utils.sheet_to_json(sh)[0]);
        }
      }
    };

    $scope.error = function (e) {
      /* DO SOMETHING WHEN ERROR IS THROWN */
      console.log(e);
    };

}